<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="content">
				个人中心
			</block>
		</cu-custom>
		<a-lists :keys="keys" :value="info">
			<template #portraitPhoto="{row,index,value}">
				<view class="image-box">
					<text class="image iconfont icon-jia"></text>
					<image class="image" :src="$http.baseURL + value" @click='setPhoto(value)'></image>
				</view>
			</template>
		</a-lists>
		<view class="out">
			<a-button class="btn" @click="out">重新登录</a-button>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			//获取 当前用户信息
			this.$http.get('').then(res=>{
				this.userInfo = res;
				this.$store.commit('SAVEUSER',{
					...res
				});
			});
		},
		data() {
			return {
				userInfo:{},
				keys: [{
						lable: '姓名',
						key: "name"
					},
					{
						lable:'人像照片',
						key:'photo',
						slot:'portraitPhoto'
					},
					{
						lable: '姓别',
						key: "sex"
					}, {
						lable: '电话',
						key: "telephone"
					}, {
						lable: '生日',
						key: "birthday"
					},
					{
						lable: '婚姻',
						key: "marriage"
					},
					{
						lable: '教龄',
						key: "TeachingAge"
					},
					{
						lable: '密码设置',
						key: "passwordSetting"
					}
				]
			}
		},
		computed: {
			info() {
				return {
					...this.$store.state.userInfo,
					...this.userInfo
				}
			}
		},
		methods: {
			out() {
				return this.$store.dispatch('logout').then(res => {
					return this.$store.dispatch('login');
				});
			},
			setPhoto(e){
				uni.navigateTo({
					url:'./setPhoto?photo='+e
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		display: flex;
		align-items: center;
		padding: 15px;
		color: #000;
		font-size: 18px;
		position: relative;

		&::after {
			content: '';
			position: absolute;
			left: 10px;
			right: 0;
			bottom: 0;
			transform: scaleY(.3);
			border-bottom: 1px solid rgba(0, 0, 0, .2);
		}

		.value {
			color: #999999;
			flex: 1;
			text-align: right;
		}
	}

	.out {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;

		.btn {
			width: 60%;
			margin: 15px auto;
			background: linear-gradient(90deg, rgba(255, 85, 127, .8) 0%, rgba(255, 0, 0, .8) 100%);
		}
	}
	.image-box{
		position: relative;
		width: 50px;
		height: 50px;
		float: right;
		border-radius: 50%;
		overflow: hidden;
		box-sizing: content-box;
		.image{
			position: absolute;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			height: 100%;
			width: 100%;
			margin: auto;
			color: #b0b0b0;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 46px;
		}
	}
</style>
